Chris Pollett > Old Classes >
CS158a

( Print View )

Student Corner:
  [Grades Sec1]
  [Grades Sec2]

  [Submit Sec1]
  [Submit Sec2]

  [Class Sign up Sec1]
  [Class Sign up Sec2]

  [
Lecture Notes]

  [Discussion Board]

  [Announcements]

Course Info:
  [Texts & Links]
  [Topics/Outcomes]
  [Outcomes Matrix]
  [Grading]
  [HW Info]
  [Exam Info]
  [Regrades]
  [Honesty]
  [Additional Policies]

HW Assignments:
  [Hw1]  [Hw2]  [Hw3]
  [Hw4]  [Hw5]

Practice Exams:
  [Mid1]  [Mid2]  [Final]

                           












HW#2 --- last modified February 28 2019 23:13:19..

Solution set.

Due date: Mar 5

Files to be submitted:
  Hw2.pdf
  Hw2.zip

Purpose: To learn various issues concerning the physical and data link layers such as bandwidth versus data rate, transmission technologies, and sliding window protocols.

Related Course Outcomes:

(3) Analyze the performance metrics of networks, including bandwidth, delay, and error rate.

(5) Develop a software simulator for local area network protocols.

Specification:

This homework involves two components: First I'd like you to do the following book problems: Ch 2 #3, #11, #22, #53. Ch3 # 13. Submit these in Hw2.pdf. For the second component of the homework, I'd like you to write a Java program to simulate the 1-bit sliding window protocol and do some experiments with it. Your source code should be submitted in the file Hw2.zip. Your program should be compilable by extracting this folder and typing javac *.java. To run your program I should be able to type:

java SlidingSimulator test.txt

Here test.txt is the name of a test file used by the simulator. A summary of the results of your experiments should be put into the Hw2.pdf file mentioned above. Your program should consist of at least the following classes:

SlidingSimulator -- this is the main driver program which runs the simulation. The main method of this class first reads the file test.txt. The file test.txt has the format:

total_time
Name1
message of machine1
error_rate1
timeout1
delay1
Name2
message of machine2
error_rate2
timeout2
delay2

An example file might look like:

10000
Machine1
The quick brown fox
.56
2000
1000
Machine2
jumped over the lazy dog
.01
1000
500

Here total_time is supposed to be the total duration of the simulation in milliseconds. The next five lines are the five arguments for the constructor of a DataLinkLayer, and the five lines after that are the five arguments of a constructor of a second DataLinkLayer. The main method of SlidingSimulator instantiates two DataLinkLayer's, then constructs a PhysicalLayer based on these two objects. It then creates anonymous inner subclass of the Java class Timer while will go off after total_time, and starts this Timer. The actionPerformed method of this subclass of Timer calls System.exit(0) to stop the program. After starting the Timer, the main method then calls the protocol4 methods of each DataLinkLayer object.

Frame -- this is essentially the struct on page 202 of the book converted to a Java class. You can make accessor functions to get and set its fields. If you like, make it a Java Bean. The info field should be able to hold one char. That is, for our project wherever the packet struct of the book is used, you can instead use a char.

EventType -- this corresponds to the books event_type struct. This can be an enum (Java 1.5) with three possible values FRAME_ARRIVAL, CKSUM_ERR, and TIMEOUT, NO_EVENT.

PhysicalLayer -- this class is used to send Frames from one DataLinkLayer to another. It has two DataLinkLayer fields: machine1 and machine2. It also has a field currentFrame which is initially null. The constructor for this class takes two DataLinkLayer's and sets them into machine1 and machine2. These two machines are then connected. Our PhysicalLayer class only supports communication between two machines. Besides setting the value of the machine1 and machine2 fields, the constructor of PhysicalLayer also calls machine1.setPhysicalLayer(this) and machine2.setPhysicalLayer(this). This is so these DataLinkLayer objects know to which PhysicalLayer they are attached. Your PhysicalLayer class should also have a method with signature public void send(Frame frame, DataLinkLayer m). The idea of this method is that Frame f is coming from the machine m destined for the other machine. This method first sets currentFrame = f and then checks the two DataLinkLayer objects to find one whose reference is not equal to m. It calls that DataLinkLayer's setEventType(FRAME_ARRIVAL). If send() is called twice before currentFrame is accessed, both DataLinkLayer's setEventType(CKSUM_ERR) method should be called. This can be enforced by making sure the DataLinkLayer's use a mutator method for the currentFrame which checks this.

DataLinkLayer -- This class is supposed to represent the DataLinkLayer on one machine. The constructor for the DataLinkLayer takes five arguments: name -- a String name for the machine that it is the DataLinkLayer for, a String packetStream which is supposed to store all the packets which will eventually be sent, error_rate -- this is a float for the probability that a frame to this machine will have an error, timeout -- how long this layer will wait before resend a frame, and delay -- this is an int which says how long in milliseconds it takes before an Event is processed. The values of these variables are stored in DataLinkLayer fields. DataLinkLayer in addition has the following public methods: setPhysicalLayer, setEventType, protocol4, toNetworkLayer, fromNetworkLayer, toPhysicalLayer, fromPhysicalLayer, startTimer, stopTimer, inc, and waitForEvent. These methods (except setPhysicalLayer and setEventType) roughly correspond to the functions called in the protocol4 function on page 215 of your book, but were we've given names that follow the CS Department naming conventions: i.e., toNetworkLayer rather than to_network_layer. The method setPhysicalLayer(PhysicalLayer p) sets p in a field called media. The method setEventType(EventType e) sets the currentEvent field to be e. The method protocol4 should be a Java implementation of the function protocol4 with some modifications. First, you can assume the seq_nr type is just an int. Then rather than have a while loop instead you should set up and start an anonymous inner subclass of Timer whose ActionListener's actionPerformed method is called every delay milliseconds. The actionPerformed method then does the contents of what was in the book's while loop. In the if(event==FRAME_ARRIVAL) block, if neither subcase applies we know that there must have been an error in the frame, so you should set event=CKSUM_ERR. The last thing that needs to be modified is that the last five lines of the book's while loop should be in an if block where the if checks that the EventType is not either CKSUM_ERR or NO_EVENT. The function toNetworkLayer System.out.println's the name of the machine, the words "Network Layer Received:" followed by the char packet received. The function fromNetworkLayer returns the next char out of the String packetStream. i.e., the first time this method is called the first char of the String packetStream is returned, the next time the second char of packetStream is return and so on. The method toPhysicalLayer(Frame s) calls media.send(s, this) . It also System.out.println's the name of the machine, the phrase "DataLink Layer sent frame:" and the contents of the frame. The method fromPhysicalLayer() first computes a random value between 0 and 1 and checks if this is less than the errorRate field. If it is, then both the sequence numbers seq and ack of the Frame media.currentFrame are set to the bogus value of -1. Otherwise, they are left unchanged. The fromPhysicalLayer() method then should echo using System.out.println, the name of the machine, the phrase "DataLink Layer Received frame:" and then then contents of the frame. Finally, the method returns media.currentFrame. The method startTimer starts the Timer timeoutTimer, which is a field of the DataLinkLayer. timeoutTimer should have been instantiated as an anonymous inner subclass of Timer in the constructor of the DataLinkLayer so that its ActionListener's actionPerformed method will be called after timeout millicseconds. The actionPerformed method of this Timer subclass calls setEventType(TIME_OUT), then call this.stop() so that the actionPerformed method is only called once. The method stopTimer calls timeoutTimer.stop(). The method inc inverts the supplied sequence number. The method WaitForEvent sets event=currentEvent then sets currentEvent=NO_EVENT, then returns event.

You should do experiments (and write them up) where you vary the error rate of both machines. For instance, you can try having both machines with no frame errors, then one machine with some errors, the other without, and then both machines having errors. You can also vary the size of the error. You should also do experiments (and write them up) where you vary the ratio of the delay's versus timeout times for both machines. You should try to draw meaningful conclusions from the data of your experiments.

Point Breakdown

Book problems (1pt each) 5pts
Your source code follows the Departmental Java Coding Guidelines 1pt
You have each of the classes described, SlidingSimulator main is as described 1pt
Sliding window protocol correctly implemented 2pts
Write-up of experiments 1pt
Total10pts